package com.acme.bankapp.service.email;

import com.acme.bankapp.domain.client.*;
import com.acme.bankapp.domain.email.Email;
import com.acme.bankapp.domain.email.Queue;

public class EmailService extends Thread {
	private Queue queue = new Queue();
	
	public EmailService() {
		this.start();
	}
	
	public void run() {
		Email email;
		
		while(true) {
			email = this.queue.getEmail();
			if(email == null) {
				return;
			}
			
			// send email
		}
	}
	
	public void sendNotificationEmail(Client client, String from, String to, String subject, String message) {
		Email email = new Email(client);
		
		email.setFrom(from);
		email.setTo(to);
		email.setSubject(subject);
		email.setMessage(message);
		
		this.queue.add(email);
	}
	
	public void close() {
		this.queue.close();
	}
}
